package problems;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import lib.MathLib;

public class Euler023 extends AbstractEuler {

	@Override
	public Number calculate() {
		
		List<Long> abundants = new ArrayList<Long>();
		List<Long> allNumbers = new ArrayList<Long>();
		
		for (long i = 1; i <= 28123; i++) {
			allNumbers.add(i);
			List<Long> divisors = MathLib.getProperDivisors(i);
			if (MathLib.getSum(divisors) > i) {
				abundants.add(i);
			}
		}

		Set<Long> sumsOfAbundants = new HashSet<Long>();

		for (int i = 0; i < abundants.size(); i++) {
			for (int j = 0; j < abundants.size(); j++) {
				Long sum = abundants.get(i) + abundants.get(j);
				if (sum <= 28123) sumsOfAbundants.add(sum);
			}
		}
	
		allNumbers.removeAll(sumsOfAbundants);
		
		return MathLib.getSum(allNumbers);
	}

	@Override
	protected Number getCorrectAnswer() {
		return 4179871L;
	}

}
